﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;

namespace SharpSoft.Documentation.Html.CSS
{
    /// <summary>
    /// Css属性集合
    /// </summary>
    public class CssPropertyCollection : IDictionary<string, string>
    {
        private readonly Dictionary<string, string> dic = new Dictionary<string, string>();
        public CssPropertyCollection()
        {

        }


        public void Add(string key, string value)
        {
            key = key.ToLower();
            if (!dic.ContainsKey(key))
            {
                dic.Add(key, value);
            }
            else
            {
                dic[key] = value;
            }
        }

        public bool ContainsKey(string key)
        {
            return dic.ContainsKey(key.ToLower());
        }

        public ICollection<string> Keys
        {
            get { return dic.Keys; }
        }

        public bool Remove(string key)
        {
            return dic.Remove(key.ToLower());
        }

        public bool TryGetValue(string key, out string value)
        {
            return dic.TryGetValue(key.ToLower(), out value);
        }

        public ICollection<string> Values
        {
            get { return dic.Values; }
        }

        public string this[string key]
        {
            get
            {
                return dic[key.ToLower()];
            }
            set
            {
                this.Add(key, value);
            }
        }

        public void Add(KeyValuePair<string, string> item)
        {
            this.Add(item.Key, item.Value);
        }

        public void Clear()
        {
            dic.Clear();
        }

        public bool Contains(KeyValuePair<string, string> item)
        {
            return dic.Contains(item);
        }

        public void CopyTo(KeyValuePair<string, string>[] array, int arrayIndex)
        {

        }

        public int Count
        {
            get { return dic.Count; }
        }

        public bool IsReadOnly
        {
            get { return false; }
        }

        public bool Remove(KeyValuePair<string, string> item)
        {
            return this.Remove(item.Key);
        }

        public IEnumerator<KeyValuePair<string, string>> GetEnumerator()
        {
            return dic.GetEnumerator();
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return this.GetEnumerator();
        }
    }
}
